const path = require('path')
const fs = require('fs')

function myReadfile (url) {
  var data = fs.readFileSync(url).toString()
  return data
}

function myWriteFile (url,data) {
  fs.writeFileSync(url,data)
}

function read(url) {
  fs.readdir(url,(err,data) => {
    if (err) {
      console.log(err)   
    } else {
      data.forEach(dir => {
        fs.stat(url+'/'+dir,(err,stats)=>{
          if(err){
            console.log(err)
          }else{
            if(stats.isFile()){
              var r = myReadfile(url+'/'+dir)
              var tx = r.replace(/(\d+)px/g,function(a,b){
                return b/100 + 'rem'
              })
              myWriteFile(url+'/'+dir,tx)
            }else{
              read(url+'/'+dir) 
            }
          }
        })
      })
    }
  })
}

read('./views')